﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Commonlib;


namespace AlbonWeb.Admin
{
    public partial class ErrorLog : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { 
                ViewState["limit"]="where 1=1";
                bindRep();
            }
        }
        protected void bindRep()
        {
            if (userName.Text.Trim() != "")
            {
                ViewState["limit"] += " and userName like '%"+userName.Text.Trim()+"%'";
            }
            if (startDate.Text != "")
            {
                ViewState["limit"] += " and createDate>'"+startDate.Text+"'";
            }
            if (endDate.Text != "")
            {
                ViewState["limit"] += " and createDate<'"+endDate.Text+"'";
            }
            string cmdstr="select count(*) from Error "+ViewState["limit"].ToString();
            AspNetPager1.RecordCount=int.Parse(SqlHelper.ExecuteScalar(SqlHelper.SqlConnectionString,CommandType.Text,cmdstr,null).ToString());
            SqlParameter[] parameters=new SqlParameter[]{
                new SqlParameter("@tablename","Error"),
                new SqlParameter("@startIndex",AspNetPager1.StartRecordIndex),
                new  SqlParameter("@endIndex",AspNetPager1.EndRecordIndex),
                new SqlParameter("@limit",ViewState["limit"].ToString()),
                new SqlParameter("@orderby","createDate desc")
            };
            SqlHelper.BindRepeater(repMain, SqlHelper.SqlConnectionString, CommandType.StoredProcedure,"netpager",parameters);
            
        }
        //换页
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            bindRep();
        }


        //执行查询
        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            ViewState["limit"] = "where 1=1";
            bindRep();
            AspNetPager1.CurrentPageIndex = 1;
        }
    }
}